home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / AIAT 1.0.1 / Examples / Sources / PowerPlantStorage / PowerPlantStoreStream.cp < prev    next >
Encoding:
Text File  |  1997-09-11  |  1.9 KB  |  56 lines  |  [TEXT/CWIE]

  1. // PowerPlantStoreStream.cp
  2. //    Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4.  
  5. // Subclass of HFSStoreStream that uses PowerPlant's support for threaded, asynch i/o.
  6.  
  7. #include "PowerPlantStoreStream.h"
  8. #include <LThread.h>
  9. #include <Errors.h>
  10.  
  11. PowerPlantStoreStream::PowerPlantStoreStream(short v, long d, const StringPtr n, OSType c, OSType t)
  12.     : HFSStoreStream(v,d,n,c,t) {
  13. }
  14.  
  15. PowerPlantStoreStream::PowerPlantStoreStream(short v, long d, const StringPtr n,
  16.                                              OSType c, OSType t, bool o, bool w, short f)
  17.     : HFSStoreStream(v,d,n,c,t,o,w,f) {
  18. }
  19.  
  20. IAStoreStream* PowerPlantStoreStream::Clone() {
  21.     return new PowerPlantStoreStream(vRefNum, dirID, fileName, creator, fileType,
  22.                                      isOpen, isWritable, fRefNum);
  23. }
  24.  
  25. void PowerPlantStoreStream::Write(uint32 address, const byte* data, uint32 length) {
  26.     IAThrowIfNot(isOpen && isWritable, StoreError);
  27.     SThreadParamBlk pb;
  28.     LThread* thread = LThread::GetCurrentThread();
  29.     thread->SetupAsynchronousResume(&pb);
  30.     pb.ioPB.F.ioParam.ioRefNum = fRefNum;
  31.     pb.ioPB.F.ioParam.ioBuffer = (Ptr)data;
  32.     pb.ioPB.F.ioParam.ioReqCount = length;
  33.     pb.ioPB.F.ioParam.ioPosMode = fsFromStart;
  34.     pb.ioPB.F.ioParam.ioPosOffset = address;
  35.     PBWrite(&pb.ioPB.F, true);
  36.     OSErr err = thread->SuspendUntilAsyncResume(&pb);
  37.     IAThrowIf(err, StoreError);
  38.     IAAssert(pb.ioPB.F.ioParam.ioActCount = length);
  39. }
  40.  
  41. uint32 PowerPlantStoreStream::Read(uint32 address, byte* data,  uint32 length) {
  42.     IAThrowIfNot(isOpen, StoreError);
  43.     SThreadParamBlk pb;
  44.     LThread* thread = LThread::GetCurrentThread();
  45.     thread->SetupAsynchronousResume(&pb);
  46.     pb.ioPB.F.ioParam.ioRefNum = fRefNum;
  47.     pb.ioPB.F.ioParam.ioBuffer = (Ptr)data;
  48.     pb.ioPB.F.ioParam.ioReqCount = length;
  49.     pb.ioPB.F.ioParam.ioPosMode = fsFromStart;
  50.     pb.ioPB.F.ioParam.ioPosOffset = address;
  51.     PBRead(&pb.ioPB.F, true);
  52.     OSErr err = thread->SuspendUntilAsyncResume(&pb);
  53.     IAThrowIf(err && err != eofErr, StoreError);
  54.     return pb.ioPB.F.ioParam.ioActCount;
  55. }
  56.